package com.myworkspace.standard.common.utils;

import redis.clients.jedis.Jedis;

public class ThreadLocalUtil {

    //ThreadLocal.withInitial(RedisClientUtil::getClient)
    private static ThreadLocal<Jedis> localJedis = new ThreadLocal<>();

    public static Jedis getLocalJedis() {
        if (localJedis.get() == null) {
            localJedis.set(RedisClientUtil.getClient());
        }
        return localJedis.get();
    }

    public static void closeLocalJedis() {
        Jedis redis = localJedis.get();
        if (redis != null) {
            localJedis.remove();
            redis.close();
        }
    }

}
